<?php
    #-------------------------------------------------------------#
	# This file is part of the Kumomado - Virtual Window Platform #
	# for PHP. (c) 2009 Tsai, Min Che <tirme0812@gmail.com>       #
	# Please visit http://www.kumomado.org/ for more information. #
	#                                                             #
	# This software is licensed under the GNU License v3. Please  #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#

	Kumomado::load('Kui.Components.Base.KumomadoUIBase');
	/**
	 * Open a new kumomado window by arguments
	 */
	define('OPEN_WINDOW', 'openWindow');
	/**
	 * Open an URL in the browser
	 */
	define('OPEN_URL', 'openURL');
	/**
	 * @package libraries/kui/components/base/
	 * @author Tsai, Min Che
	 * @version 1.0
	 */
	class KumomadoButton extends KumomadoUIBase {
		/**
		 * @var string
		 */
		protected $ui_name = 'KButton';
		/**
		 * @var string
		 */
		protected $value = '';
		/**
		 * @var string
		 */
		protected $event_type = 'openWindow';
		/**
		 * @var array
		 */
		protected $params = array();
		/**
		 * @var array
		 */
		protected $render = null;
		/**
		 * 
		 * @param string $id
		 * @param string $value
		 * @param string $event_type
		 */
		public function __construct($id, $value, $event_type = 'openWindow') {
			$this->setId($id);
			$this->setValue($value);
			$this->setEventType($event_type);
		}
		/**
		 * @param string $value
		 */
		public function setValue($value) {
			$this->value = $value;
		}
		/**
		 * @return string
		 */
		public function getValue() {
			return $this->value;
		}
		/**
		 * @param string $event_type
		 */
		public function setEventType($event_type = 'openWindow') {
			$this->event_type = $event_type;
		}
		/**
		 * @return string
		 */
		public function getEventType() {
			return $this->event_type;
		}
		/**
		 * @param array $params
		 */
		public function setParams($params) {
			$this->params = $params;
		}
		/**
		 * @return array
		 */
		public function getParams() {
			return (array)$this->params;
		}
		public function getAttrs() {
			return array(
				'id' => $this->getId(),
				'event_type' => $this->getEventType(),
				'params' => $this->getParams()
			);
		}
		/**
		 * @return string
		 */
		public function view() {
			$view = '<input type="button" id="'.$this->getId().'" value="'.$this->getValue().'">';
			return $view;
		}
		/**
		 * @return array
		 */
		public function render() {
			if ($this->render == null) {
				$this->render = array(
					'ui_name' => $this->ui_name,
					'attrs' => $this->getAttrs(),
					'view' => $this->view()
				);
			}
			$kuiClient = KumomadoUIClient::getInstance();
			$kuiClient->register($this->getId(), $this->render);
			return $this->render;
		}
	}
?>